const { envList } = require('../../envList');

// pages/me/index.js
Page({
  data: {
    openId: '',
    showUploadTip: false,
  },

  onLoad: function () {
    // 初始化云开发环境
    wx.cloud.init({
      env: 'golden-marry-9gjgh026bbc585f4', // 替换为你的环境ID
    })
  },
  addCloud(){
    wx.cloud.callFunction({
        name:'add',
        data:{
          a:1,
          b:2
        },
        success(res) {
          // 调用成功的回调
          wx.showToast({
            title: '云返回：'+res.result.sum,
            icon: 'success',
            duration: 2000//持续的时间
          })
        }
      })
  },

  getOpenId() {
    wx.showLoading({
      title: '',
    });
    //此处调用了云函数quickstart
    wx.cloud
      .callFunction({
        name: 'quickstartFunctions',
        data: {
          type: 'getOpenId',
        },
      })
      .then((resp) => {
        this.setData({
          haveGetOpenId: true,
          openId: resp.result.openid,
        });
        wx.hideLoading();
      })
      .catch((e) => {
        this.setData({
          showUploadTip: true,
        });
        wx.hideLoading();
      });
  },

  gotoWxCodePage() {
    wx.navigateTo({
      url: `/pages/exampleDetail/index?envId=${envList?.[0]?.envId}&type=getMiniProgramCode`,
    });
  },
});
